package cn.com.elite;

import java.net.URL;
import java.util.Properties;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServlet;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

public class EliteServlet extends HttpServlet{
	public static void main(String[] args){
		EliteServlet eliteServlet=new EliteServlet();
		System.out.println(eliteServlet.test());
//		  ApplicationContext ac=new ClassPathXmlApplicationContext("elitedblink.xml");
//        cn.com.elite.EliteBean1 ebeana=(cn.com.elite.EliteBean1)ac.getBean("ebeana"); 
//        cn.com.elite.EliteBean2 ebeanb=(cn.com.elite.EliteBean2)ac.getBean("ebeanb"); 	
//        EliteDBLink.ebeana=ebeana;
//        EliteDBLink.ebeanb=ebeanb;
//        EliteServlet elite=new EliteServlet();
//        EliteDBLink.setAddress(elite.test());
//        EliteRun.StartRun();
		
	}
	public String test(){
		URL a=this.getClass().getResource("elitedb.properties");
		String url=a.toString();
		return url.substring(6,url.length());
	}
	public void init(){
		String AUTO=this.getInitParameter("AUTO");
		String ADDRESS=this.getInitParameter("ADDRESS");
		String Time=this.getInitParameter("TIME");
		String CYCLE=this.getInitParameter("CYCLE");
		if(AUTO.equals("TRUE")){
			EliteDBLink.setAuto(true);
		}else if(AUTO.equals("FALSE")){
			EliteDBLink.setAuto(false);
		}
		EliteDBLink.setTime(Time);
		EliteDBLink.setAddress(ADDRESS);
		EliteDBLink.setCYCLE(CYCLE);
//		try{
//			ServletContext application;   
//	        WebApplicationContext wac;   
//	        application = getServletContext();   
//	        wac = WebApplicationContextUtils.getWebApplicationContext(application);//获取spring的context  
//	        cn.com.elite.EliteBean1 ebeana = (cn.com.elite.EliteBean1) wac.getBean("ebeana"); 
//	        cn.com.elite.EliteBean2 ebeanb = (cn.com.elite.EliteBean2) wac.getBean("ebeanb"); 	        
//		}catch(Exception e){
//			e.printStackTrace();
//		}
		EliteRun.StartRun();
	}

}
